<extend name='./Base' />
<block name='admin-content-body'>
	
	<div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">友情链接</strong> / <small>Links</small></div>
      </div>

      <hr>

      <div class="am-g">
        <div class="am-u-sm-12">
            <table class="am-table am-table-striped am-table-hover">
              <thead>
              <tr>
                <th class="table-id">ID</th>
                <th class="table-title">标题</th>
                <th class="table-type">地址</th>
                <th class="table-type">简介</th>
                <th class="table-date am-hide-sm-only">创建日期</th>
                <th class="table-set">状态</th>
                <th class="table-set">删除</th>
              </tr>
              </thead>
              <tbody>
                <foreach name="links" item='l'>
              <tr id="{$l['id']}_links">
                <td>{$l['id']}</td>
                <td>
                  <input type="text" style="border: none;" name="name" value="{$l['name']}" onchange="upl({$l['id']},'name',this)" class="am-form-field">
                </td>
                <td>
                  <input type="text" style="border: none;" name="link" value="{$l['link']}" onchange="upl({$l['id']},'link',this)" class="am-form-field">
                </td>
                <td class="am-hide-sm-only">
                <button class="am-btn am-btn-success"
                          data-am-popover="{theme: 'primary',content: '{$l['describe']|str_replace='，','<br>',###}', trigger: 'hover focus'}">
                    查看
                  </button></td>
                <td class="am-hide-sm-only">{$l['create_time']|date='Y-m-d H:i:s',###}</td>
                <td>
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                    <if condition="$l['status'] eq 1">
                      <button class="am-btn am-btn-success am-btn-xs  am-hide-sm-only" onclick="chstatus({$l['id']},this)"><span class="am-icon-trash-o"></span> 通过</button>
                      <else />
                      <button class="am-btn am-btn-danger am-btn-xs am-hide-sm-only" onclick="chstatus({$l['id']},this)"><span class="am-icon-trash-o"></span> 未通过</button>
                      </if>
                    </div>
                  </div>
                </td>
                <td>
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                      <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="deletel({$l['id']})"><span class="am-icon-trash-o"></span> 删除</button>
                    </div>
                  </div>
                </td>
              </tr>
             </foreach>
              </tbody>
            </table>
        </div>

      </div>
    </div>

</block>

<block name="js">
	<script type="text/javascript">
   function upl(id,field,obj){
    $.post('{:U("links/updatefield")}',{'field':field,'value':obj.value,'id':id,'update':1},function(res){
      if(res.status){
        layer.msg(res.msg);
      }else{
        layer.alert(res.msg);
      }
    });
  }
    function chstatus(id,obj){
      $.post('{:U("links/status")}',{'id':id},function(res){
        if(res.status){
          if(res.data==0){
            //停用
            $(obj).removeClass('am-btn-success').addClass('am-btn-danger').html('<span class="am-icon-trash-o"></span> 未通过');
          }else{
            //可用
            $(obj).removeClass('am-btn-danger').addClass('am-btn-success').html('<span class="am-icon-trash-o"></span> 通过');
          }
          layer.msg(res.msg);
          deleteCache();
        }else{
          layer.alert(res.msg,{icon:5});
        }
      });
    }
   function deletel(id) {
      layer.confirm('确定要删除？不可恢复', {
        btn: ['确定','取消']
      },function(){
        $.post('{:U("links/deletelink")}',{'id':id,'delete':1},function(res){
          if(res.status){
            $("#"+id+"_links").remove();
            layer.msg(res.msg);
            deleteCache();
          }else{
            layer.alert(res.msg,{icon:5});
          }
        });
    },function(){})
   } 
  </script>
</block>